package com.xyazm.customer.mq.consumer;

import com.xyazm.common.constants.RocketMqConstant;
import com.xyazm.common.enums.RocketMqTopicEnum;
import com.xyazm.customer.mq.config.RocketMQProperties;
import com.xyazm.customer.mq.consumer.listener.AfterSaleCustomerAuditListener;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Configuration
public class ConsumerConfig {

    @Autowired
    private RocketMQProperties rocketMQProperties;

    /**
     * 客服接收售后申请消费者
     */
    @Bean("afterSaleCustomerAudit")
    public DefaultMQPushConsumer afterSaleCustomerAudit(AfterSaleCustomerAuditListener afterSaleCustomerAuditListener)
            throws MQClientException {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(RocketMqConstant.AFTER_SALE_CUSTOMER_AUDIT_CONSUMER_GROUP);
        consumer.setNamesrvAddr(rocketMQProperties.getNameServer());
        consumer.subscribe(RocketMqConstant.AFTER_SALE_CUSTOMER_AUDIT_TOPIC, "*");
        consumer.registerMessageListener(afterSaleCustomerAuditListener);
        consumer.start();
        return consumer;
    }
}
